#ifndef _KLTFLOW_H_
#define _KLTFLOW_H_


#include <stdio.h>
#include <stdlib.h>
#include <list>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <dirent.h>
#include <unistd.h>
#include <sys/param.h>
#include <klt.h>
#include <limits>
#include "Opencv.h"


using namespace std;



class KLT
{
 public:
  KLT_TrackingContext tc;
  KLT_FeatureList fl;
  int fn; 
  unsigned char *buf,*gbuf,*ogbuf;
  int width, height;
  int xidx;
  float **bfl;
  IplImage temp;
  IplImage *capture_image;
 public:
  KLT()
    {
      tc = KLTCreateTrackingContext();
      tc->sequentialMode=TRUE;
      fn = 200;
      fl = KLTCreateFeatureList(fn);
      bfl = (float **)malloc(sizeof (float*)*fn);
      for(int i=0; i<fn; i++)
	bfl[i]= (float *)malloc(sizeof(float)*2);
    }

  ~KLT()
    {
      KLTFreeFeatureList(fl);
      KLTFreeTrackingContext(tc);
      free(gbuf);
      free(ogbuf);
      //cvReleaseImage(&(&temp));
      cvReleaseImage(&capture_image);

    }

  void setImageParam(cv::Mat input);

  void calcKlt(cv::Mat input);

  void getFlowPoint(vector<Point2f> *flowPoint);

  void getFlowScale(vector<Point2f> *flowScale);

  int getFeatureNum(){return fn;}

  void setFeatureNum(int num);

  void firstProc(int firstImCount, cv::Mat srcimage);

  void Proc(std::string dirname, int imcount, cv::Mat& output,vector<Point2f> &flowPoint,vector<Point2f> &flowscale);

};

#endif
